package com.zhongwang.mms.module.buy.controller;

import com.zhongwang.mms.base.BaseController;
import com.zhongwang.mms.common.JsonResult;
import com.zhongwang.mms.module.buy.model.ShoppingPlanModel;
import com.zhongwang.mms.module.buy.service.OuterReturnService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Description: 外购件回货确认
 * 查看 -> plan:buyretconfirm:view
 * 预入库 -> plan:buyretconfirm:prestorage
 * 回货确认 -> plan:buyretconfirm:confirm
 * 金额显示权限 -> plan:amount:view
 *
 * @Author: China.sgl
 * @Date: 2020/4/7 14:42
 */
@SuppressWarnings("ALL")
@Controller
@RequestMapping("/buy/outerReturn")
public class OuterReturnController extends BaseController {

    @Autowired
    private OuterReturnService service;

    /**
     * 外购件回货页面
     *
     * @return 路径
     */
    @GetMapping
    @RequiresPermissions({"plan:buyretconfirm:view"})
    public String page() {
        return "buy/outerReturn/page";
    }

    /**
     * 外购件回货列表数据
     *
     * @param shoppingPlanModel 查询条件
     * @return list
     */
    @ResponseBody
    @PostMapping("/list")
    @RequiresPermissions({"plan:buyretconfirm:view"})
    public JsonResult list(ShoppingPlanModel shoppingPlanModel) {
        startPage();
        List<ShoppingPlanModel> list = service.findOuterReturnList(shoppingPlanModel);
        return jsonResult(list);
    }

    /**
     * 查询所有入库记录
     *
     * @param shoppingPlanModel 查询条件
     * @return list
     */
    @ResponseBody
    @PostMapping("/store/list")
    @RequiresPermissions({"plan:buyretconfirm:view"})
    public JsonResult storeList(ShoppingPlanModel shoppingPlanModel) {
        startPage();
        List<ShoppingPlanModel> list = service.findOrderDetail(shoppingPlanModel);
        return jsonResult(list);
    }

    /**
     * 确认回货
     *
     * @param sppId 采购计划主键
     * @param odaId 入库主键
     * @return json
     */
    @ResponseBody
    @PostMapping("/submit")
    @RequiresPermissions({"plan:buyretconfirm:confirm"})
    public JsonResult submit(Integer sppId, Integer odaId) {
        return jsonResult(service.submitReturn(sppId, odaId));
    }

    /**
     * 批量确认回货
     *
     * @param id 主键
     * @return json
     */
    @ResponseBody
    @PostMapping("/submit/all")
    @RequiresPermissions({"plan:buyretconfirm:confirm"})
    public JsonResult submit(Integer[] sppId, Integer[] odaId) {
        return jsonResult(service.submitReturn(sppId, odaId));
    }

    /**
     * 撤消回货确认
     *
     * @param id 主键
     * @return json
     */
    @ResponseBody
    @PostMapping("/cancel")
    @RequiresPermissions({"plan:buyretconfirm:confirm"})
    public JsonResult cancel(Integer id) {
        return jsonResult(service.cancelRetrun(id));
    }

    /**
     * 预入库
     *
     * @param id 主键
     * @return json
     */
    @ResponseBody
    @PostMapping("/pre")
    @RequiresPermissions({"plan:buyretconfirm:prestorage"})
    public JsonResult pre(Integer id) {
        return jsonResult(service.pre(id));
    }

    /**
     * 批量预入库
     *
     * @param ids 主键数组
     * @return json
     */
    @ResponseBody
    @PostMapping("/pre/all")
    @RequiresPermissions({"plan:buyretconfirm:prestorage"})
    public JsonResult pre(Integer[] ids) {
        return jsonResult(service.pre(ids));
    }

    /**
     * 撤消预放库
     *
     * @param id 主键
     * @return json
     */
    @ResponseBody
    @PostMapping("/cancel/pre")
    @RequiresPermissions({"plan:buyretconfirm:prestorage"})
    public JsonResult cancelPre(Integer id) {
        return jsonResult(service.cancelPre(id));
    }

    /**
     * checkProCodeAndTrackNo
     * 检测确认回货的入库信息的项目号和跟踪号与采购计划的项目号和跟踪号不同则提示
     * @param sppId
     * @param odaId
     * @return
     */
    @PostMapping("/checkProCodeAndTrackNo")
    @ResponseBody
    @RequiresPermissions({"plan:buyretconfirm:confirm"})
    public JsonResult checkProCodeAndTrackNo(Integer sppId, Integer odaId) {
        return service.checkProCodeAndTrackNo(sppId, odaId);
    }

    /**********************************************
     * @title: checkIsHaveBrand
     * @description: 检测采购计划中的提报计划是否有品牌
     * @param: []
     * @return: com.zhongwang.mms.common.JsonResult
     * @author: 徐一贺
     * @date: 2020/10/12 12:34
     * @versron: ver 1.0
     **********************************************
     */
    @ResponseBody
    @PostMapping("/checkIsHaveBrand")
    public JsonResult checkIsHaveBrand(Integer sppId){
        return service.checkIsHaveBrand(sppId);
    }

}
